package mx.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import mx.dao.AuthDao;
import mx.entity.Auth;
import mx.service.AuthService;

/**
 * 权限service实现
 * 
 * @author ASUS
 *
 */
@Service("authService")
public class AuthServiceImpi implements AuthService {
	@Resource
	private AuthDao authDao;

	/**
	 * 通过authIds查寻角色权限
	 * 
	 * @return
	 */
	public Map <String,List<Auth>> findById(String authIds) {
		String[] ids = authIds.split(",");
		Map <String,List<Auth>> map=new HashMap <String, List<Auth>>();
		Auth auth= null;
		List<Auth> list=null;
		for (String id : ids) {
			 auth=authDao.findById(Integer.parseInt(id));
			if(!map.containsKey(auth.getGroupName())) {
				list = new ArrayList<Auth>();
				list.add(auth);
				map.put(auth.getGroupName(), list);
			}else {
				map.get(auth.getGroupName()).add(auth);
				map.put(auth.getGroupName(), map.get(auth.getGroupName()));
			}
			//list.add(authDao.findById(Integer.parseInt(id)));
		}
		return map;
	}
}
